package com.xjj.order;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author zhanghejie
 * @date 2020/7/20 15:13
 */
//1.使用注解@EnableFeignClients启用feign客户端；
@ComponentScan(basePackages = {"com.xjj"})
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableSwagger2
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }

    //一个Http客户端，属于客户端发现，负载均衡是软负载，客户端会向服务器，
    // 比如OrderController，拉取已注册的可用服务信息，然后根据负载均衡策略直接命令哪台服务器发送请求，
    // 整个过程都是在客户端完成的，并不需要服务器的参与。
    @LoadBalanced
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
